/**
 * 
 * @authors Riche
 * @date    2016-07-05 10:39:22
 * @version 1.1.0
 */

/*Vue.transition('fade', {
    enterClass: 'fadeInLeft',
    leaveClass: 'hide'
});*/

var vm=new Vue({
  el:"#app",
  data:{
    willShow:'vault',
    title:'我的金库',
    user:'',
    isLoading:true,
    pageSize:'',
    pageIndex:'',
    tabs:'',

    goldList:[],
    RankingList:[],
    exchangeList:[]

  },
  created:function(){
    var _self = this;
    // 顶部个人信息
    Common.ajaxCall({ url: "user_getUserInfo", datatype: 'json', type: 'post'}, function (data) {
      if(data.error_code==0){
          _self.user=data.data;
        
      }else{
          alert(data.msg);
      }
    });
  },
  compiled: function(){
    var _self = this;

    _self.init();
  },
  methods:{
    init:function(){
      var _self = this;
      _self.loadlist('level');
      _self.loadlist('exchange');
      _self.loadlist('record');
    },
    loadlist:function(tabs){
      var _self = this;
      var vModal,target;  //用来储存不同的tab页面对应的对象
      switch(tabs){       //根据tab的切换来设置sortType的值
        case 'exchange':
          // 最近兑换商品
          var url = 'user_getMyExchangeGoodsList';
          var data = {
            pageSize:4,
            pageIndex:1
          } 
          
          vModal = _self;
          target = _self.exchangeList;
        break;
        case 'level':// 用户星级排行
          var url = 'user_getRankingList';
          var data = {
            pageSize:3,
            pageIndex:1
          }; 

          vModal = _self;
          target = _self.RankingList;
        break;
        case 'record':  // 白金币记录
          var url = 'user_getGoldHistoryList';
          var data = {
            pageSize:3,
            pageIndex:1
          }; 

          vModal = _self;
          target = _self.goldList;
          
        break;
        default:
           
        break; 
      }

      if(!vModal.isLoading) return;
      data = Common.jsonEncode(data);
      Common.ajaxCall({ url: url, datatype: 'json', type: 'post', data: data}, function (data) {
          if(data.error_code==0 && data.data.length > 0){
              if(vModal.pageIndex==1){
                target.length = 0;
              }
              for(var i = 0; i < data.data.length; i++){
                target.push(data.data[i]);
              }
              
              
          }else{
              vModal.isLoading = false;
          }

          vModal.pageIndex++;
      });
      
    },
    fn:function(flag){
      var _self = this;
      switch(flag){
        case 'level':
          /*this.willShow = flag;
          this.title='用户星级排行榜';
          var data = {
            isLoading:true,
            pageSize:10,
            pageIndex:1,
            RankingList:[]
          };
          _self = $.extend(_self,data);
          _self.loadlist('level');*/
          window.location.href = "myRanking.html";

        break;
        case 'exchange':
          /*this.willShow = flag;
          this.title='最近兑换商品';
          var data = {
            isLoading:true,
            pageSize:10,
            pageIndex:1,
            exchangeList:[]
          };
          _self = $.extend(_self,data);
          _self.loadlist('exchange');*/
          window.location.href = "exchange.html";

        break;
        case 'record':
          /*this.willShow = flag;
          this.title='白金币记录';
          var data = {
            isLoading:true,
            pageSize:10,
            pageIndex:1,
            goldList:[]
          };
          _self = $.extend(_self,data);
          _self.loadlist('record');*/
          window.location.href = "myRecord.html";
        break;
        case 'vault':
          this.willShow = flag;
          this.title='我的金库';
        break;
      }
    },
    back:function(){
      var _self = this;
      if(this.willShow !== 'vault'){
        this.willShow = 'vault';
        this.title='我的金库';
        var data = {
          isLoading:true,
          pageSize:3,
          pageIndex:1,
          goldList:[],
          exchangeList:[],
          RankingList:[]
        };
        _self = $.extend(_self,data);
        _self.init();
      }else{
        window.history.go(-1);
      }
      
    },
    loadPhoto:function(){
        myJS.imgScale('.j_1', '1', '1');
        myJS.imgScale('.j_1511', '15', '11');
        myJS.ImgFull('.loadImg','images/liby.png');
    }
  },
  watch:{
    "willShow,RankingList,exchangeList": function(){
        this.loadPhoto();
    }
  }
});